package joe.works.commons;

/**
 * This class wraps another {@link IKeyValuePair} and enables us to convert the value 
 * @author josseyj
 *
 * @param <KeyType>
 * @param <ActualValueType>
 * @param <NewValueType>
 */
public  class KeyValueWrapper<KeyType, ActualValueType, NewValueType> implements IKeyValuePair<KeyType, NewValueType> {
	private IKeyValuePair<KeyType, ActualValueType> keyValuePair;
	private IConvertor<ActualValueType, NewValueType> valueConvertor;
	
	public void setKeyValuePair(IKeyValuePair<KeyType, ActualValueType> keyValuePair) {
		this.keyValuePair = keyValuePair;
	}
	
	public void setValueConvertor(IConvertor<ActualValueType, NewValueType> valueConvertor) {
		this.valueConvertor = valueConvertor;
	}
	
	public NewValueType getValue(KeyType key) {
		ActualValueType value = keyValuePair.getValue(key);
		return valueConvertor.convert(value);
	}

}
